package dbconnector;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;

public class Conexion_DB {

    //Declaración e Inicialización de Variables
    //JDBC driver name and database URL
    final String DATABASE_URL = "jdbc:mysql://localhost/traccion_db";
    final String USERNAME = "root";
    final String PASSWORD = "k5YMQ9LE0ldbk";
//    final String PASSWORD = "homero182";
    private Statement stmt = null;
    private ResultSet rs = null;
    
    public Conexion_DB() {
       
    }     
                
    // <editor-fold defaultstate="collapsed" desc="Conectar">
     public Connection conectar() throws SQLException{
    return  DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
           
    }
     // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Cerrar Conexión">
    public void cierraConexion() {
        //bloque Try-Catch para cerrar la conexión
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "SQLException (Cerrar Conexión): "
                    + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    // </editor-fold>
}
